package com.house.twohouse.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.house.twohouse.entity.RentalEntity;
import com.house.twohouse.service.RentalService;
import com.house.common.utils.PageUtils;
import com.house.common.utils.R;



/**
 * 
 *
 * @author wzh
 * @email sunlightcs@gmail.com
 * @date 2022-04-25 20:50:10
 */
@RestController
@RequestMapping("twohouse/rental")
public class RentalController {
    @Autowired
    private RentalService rentalService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = rentalService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{rentalId}")
    public R info(@PathVariable("rentalId") Integer rentalId){
		RentalEntity rental = rentalService.getById(rentalId);

        return R.ok().put("rental", rental);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RentalEntity rental){
		rentalService.save(rental);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RentalEntity rental){
		rentalService.updateById(rental);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] rentalIds){
		rentalService.removeByIds(Arrays.asList(rentalIds));

        return R.ok();
    }

}
